package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.AutoOutbdTaskDao;
import com.fdb.efp.nls.service.domain.AutoOutbdTask;
import com.fdb.efp.nls.service.facade.AutoOutbdTaskService;
import com.fdb.efp.nls.service.vo.AutoOutbdTaskVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 自动外呼任务				<p>
 * @author ligm
 * @date 2019-08-27
 */
@Service("autoOutbdTaskService")
public class AutoOutbdTaskServiceImpl implements AutoOutbdTaskService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(AutoOutbdTaskServiceImpl.class);

    @Autowired
    private AutoOutbdTaskDao autoOutbdTaskDao;

    /**
     * 新增操作
     */
    public int insertAutoOutbdTask(AutoOutbdTaskVO inAutoOutbdTaskVo) {
        logger.debug("当前新增数据为:"+ inAutoOutbdTaskVo.toString());
        int num = 0;
        try {
            AutoOutbdTask autoOutbdTask = new AutoOutbdTask();
            beanCopy(inAutoOutbdTaskVo, autoOutbdTask);
            num = autoOutbdTaskDao.insertAutoOutbdTask(autoOutbdTask);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:"+ num);
        return num;
    }

    /**
     * 删除操作
     */
    public int deleteByPk(AutoOutbdTaskVO inAutoOutbdTaskVo) {
        logger.debug("当前删除数据条件为:"+ inAutoOutbdTaskVo);
        int num = 0;
        try {
            AutoOutbdTask autoOutbdTask = new AutoOutbdTask();
            beanCopy(inAutoOutbdTaskVo, autoOutbdTask);
            num = autoOutbdTaskDao.deleteByPk(autoOutbdTask);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:"+ inAutoOutbdTaskVo +"删除的数据条数为"+ num);
        return num;
    }


    /**
     * 更新操作
     */
    public int updateByPk(AutoOutbdTaskVO inAutoOutbdTaskVo) {
        logger.debug("当前修改数据为:"+ inAutoOutbdTaskVo.toString());
        int num = 0;
        try {
            AutoOutbdTask autoOutbdTask = new AutoOutbdTask();
            beanCopy(inAutoOutbdTaskVo, autoOutbdTask);
            num = autoOutbdTaskDao.updateByPk(autoOutbdTask);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:"+ inAutoOutbdTaskVo +"修改的数据条数为"+ num);
        return num;
    }

    /**
     * 查询操作
     */
    public AutoOutbdTaskVO queryByPk(AutoOutbdTaskVO inAutoOutbdTaskVo) {

        logger.debug("当前查询参数信息为:"+ inAutoOutbdTaskVo);
        try {
            AutoOutbdTask queryAutoOutbdTask = new AutoOutbdTask();
            beanCopy(inAutoOutbdTaskVo, queryAutoOutbdTask);
            AutoOutbdTask queryRslAutoOutbdTask = autoOutbdTaskDao.queryByPk(queryAutoOutbdTask);
            if (Objects.nonNull(queryRslAutoOutbdTask)) {
                AutoOutbdTaskVO outAutoOutbdTaskVo = beanCopy(queryRslAutoOutbdTask, new AutoOutbdTaskVO());
                logger.debug("当前查询结果为:"+ outAutoOutbdTaskVo.toString());
                return outAutoOutbdTaskVo;
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }


    /**
     * 查询用户权限数据
     */
    @SuppressWarnings("unchecked")
    public List<AutoOutbdTaskVO> queryAllOwner(AutoOutbdTaskVO autoOutbdTaskVo) {

        logger.debug("当前查询本人所属数据信息的参数信息为:");
        List<AutoOutbdTaskVO> list = null;
        try {
            List<AutoOutbdTask> autoOutbdTasks = autoOutbdTaskDao.queryAllOwnerByPage(autoOutbdTaskVo);
            logger.debug("当前查询本人所属数据信息的结果集数量为:"+ autoOutbdTasks.size());
            pageSet(autoOutbdTasks, autoOutbdTaskVo);
            list = (List<AutoOutbdTaskVO>) beansCopy(autoOutbdTasks, AutoOutbdTaskVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }


    /**
     * 查询当前机构权限数据
     */
    @SuppressWarnings("unchecked")
    public List<AutoOutbdTaskVO> queryAllCurrOrg(AutoOutbdTaskVO autoOutbdTaskVo) {

        logger.debug("当前查询本人所属机构数据信息的参数信息为:");
        List<AutoOutbdTask> autoOutbdTasks = autoOutbdTaskDao.queryAllCurrOrgByPage(autoOutbdTaskVo);
        logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+autoOutbdTasks.size());
        List<AutoOutbdTaskVO> list = null;
        try {
            pageSet(autoOutbdTasks, autoOutbdTaskVo);
            list = (List<AutoOutbdTaskVO>) beansCopy(autoOutbdTasks, AutoOutbdTaskVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }


    /**
     * 查询当前机构及下属机构权限数据
     */
    @SuppressWarnings("unchecked")
    public List<AutoOutbdTaskVO> queryAllCurrDownOrg(AutoOutbdTaskVO autoOutbdTaskVo) {

        logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
        List<AutoOutbdTask> autoOutbdTasks = autoOutbdTaskDao.queryAllCurrDownOrgByPage(autoOutbdTaskVo);
        logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ autoOutbdTasks.size());
        List<AutoOutbdTaskVO> list = null;
        try {
            pageSet(autoOutbdTasks, autoOutbdTaskVo);
            list = (List<AutoOutbdTaskVO>) beansCopy(autoOutbdTasks, AutoOutbdTaskVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;

    }

    /**
     * 查询当前产品种类下权限数据
     */
    @SuppressWarnings("unchecked")
    public List<AutoOutbdTaskVO> queryAllCurrOwnerPrd(AutoOutbdTaskVO autoOutbdTaskVo) {
        logger.debug("当前产品种类下数据信息的参数信息为:");
        List<AutoOutbdTask> autoOutbdTasks = autoOutbdTaskDao.queryAllCurrOwnerPrdByPage(autoOutbdTaskVo);
        logger.debug("当前产品种类下数据信息的结果集数量为:"+ autoOutbdTasks.size());
        List<AutoOutbdTaskVO> list = null;
        try {
            pageSet(autoOutbdTasks, autoOutbdTaskVo);
            list = (List<AutoOutbdTaskVO>) beansCopy(autoOutbdTasks, AutoOutbdTaskVO.class);
        } catch (Exception e) {
            logger.error("数据转换出现异常!", e);
        }

        return list;
    }

}
